<!--
 * @Author: lvye
 * @Description:
 * @Date: 2023-07-28 16:01:43
 * @LastEditTime: 2023-08-21 15:14:28
 * @FilePath: \vue3-ts\src\components\NavHeader\NavHeader.vue
-->
<template>
  <div class="nav-header">
    <el-icon
      ><component
        :is="isFold ? 'Expand' : 'Fold'"
        @click="handleFoldClick"
        class="fold-menu"
      ></component
    ></el-icon>
    <div class="content">
      <hy-bread-crumb :breadcrumbs="breadcrumbs"></hy-bread-crumb>
      <user-info></user-info>
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, ref } from "vue"
import UserInfo from "./UserInfo.vue"
import HyBreadCrumb from "@/base-ui/breadcrumb"
import { useStore } from "@/store"
import { useRoute } from "vue-router"
import { pathMapBreadCrumbs } from "@/utils/map-menu"
export default defineComponent({
  emits: ["foldChange"],
  components: {
    UserInfo,
    HyBreadCrumb
  },
  setup(props, { emit }) {
    const isFold = ref(false)
    const handleFoldClick = () => {
      isFold.value = !isFold.value
      emit("foldChange", isFold.value)
    }
    const store = useStore()
    const breadcrumbs = computed(() => {
      const userMenus = store.state.login.userMenus
      const route = useRoute()
      const currentPath = route.path
      return pathMapBreadCrumbs(userMenus, currentPath)
    })

    return {
      isFold,
      handleFoldClick,
      breadcrumbs
    }
  }
})
</script>

<style lang="less">
.nav-header {
  width: 100%;
  display: flex;
  align-items: center;
  .fold-menu {
    font-size: 30px;
    cursor: pointer;
  }
  .content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    padding: 0 20px;
  }
}
</style>
